package com.fire.control.system.module.user.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.fire.control.system.dto.MessageUserDto;
import com.fire.control.system.dto.SelectUserDTO;
import com.fire.control.system.dto.UserInfo;
import com.fire.control.system.dto.app.AppUserVo;
import com.fire.control.system.entity.Company;
import com.fire.control.system.entity.User;
import com.fire.control.system.entity.UserGetuiInfo;

public interface UserMapper{
	
	@Select("select token from t_user_token where user_id=#{userId}")
	public String getUserToken(@Param("userId")String userId);
	
	@Insert("insert into t_user_token(id,user_id,token) values(UUID(),#{userId},#{token})")
	public int insertUserToken(@Param("userId")String userId,@Param("token")String token);
	
	@Update("update t_user_token set token=#{token} where user_id=#{userId}")
	public int updateUserToken(@Param("userId")String userId,@Param("token")String token);
	
	/**
	* @Title: updateUserGetuiInfo
	* @Description: TODO(修改用户个推信息)
	* @author wanbo
	* @date  2017年6月29日 下午6:08:06
	* @param userGetuiInfo
	* @return
	*/
	public int updateUserGetuiInfo(@Param("cid")String cid,@Param("userId")String userId);
	
	/**
	* @Title: saveUserGetuiInfo
	* @Description: TODO(保存用户个推信息)
	* @author wanbo
	* @date  2017年6月29日 下午6:08:15
	* @param userGetuiInfo
	* @return
	*/
	public int saveUserGetuiInfo(UserGetuiInfo userGetuiInfo);
	
	/**
	* @Title: getUserGetuiInfo
	* @Description: TODO(获取用户个推信息)
	* @author wanbo
	* @date  2017年6月29日 下午6:08:26
	* @param userId
	* @return
	*/
	public UserGetuiInfo getUserGetuiInfo(String userId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: findById   
	 * @Description: TODO  
	 * @param:        
	 * @return: AppUserVo      
	 * @throws
	 */
	@Select("select id,name,tel_number,user_icon from t_users where id = #{userId}")
	public AppUserVo findById(String userId);
	
	@Select("select * from t_users where id = #{userId}")
	public User getById(String userId);
	
	public List<User> getAll();
	
	/**
	 * @author: xiechengguang 
	 * @Title: getCompanyByUserId   
	 * @Description: 根据用户id获取企业  
	 * @param:        
	 * @return: Company      
	 * @throws
	 */
	@Select("select c.* from t_users u, t_company c where c.status = true AND u.company_id = c.id AND u.id = #{userId}")
	public Company getCompanyByUserId(String userId);
	
	@Select("select * from t_users u where u.id = #{id}")
	public User getUserById(String id);
	
	//根据登陆账号查找用户
	@Select("select u.* from t_users u where u.login_name =#{loginName}")
	public List<User> getUserByLoginName(String loginName);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getUsers   
	 * @Description: 根据角色id和企业id获取所有对应用户  
	 * @param:        
	 * @return: List<User>      
	 * @throws
	 */
	public List<User> getUsers(@Param("roleIds") String[] roleIds, @Param("companyId") String companyId);
	
	
	/**
	* @Title: getWarningMsgUserList
	* @Description: TODO(获取报警推送人员列表)
	* @author wanbo
	* @date  2017年6月20日 上午11:17:48
	* @param msgScopeType
	* @param companyId
	* @param deviceId
	* @param msgSetRoles
	* @return
	*/
	public List<MessageUserDto> getWarningMsgUserList(@Param("msgScopeType")String msgScopeType,@Param("companyId")String companyId,@Param("deviceId")String deviceId,@Param("msgSetRoles")List<Object> msgSetRoles);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getSecurityManagers   
	 * @Description: 根据设备组id获取安全管理员  
	 */
	@Select("select u.id,u.name from t_users u left join t_user_device_group udg on u.id = udg.user_id left join t_user_role ur on u.id = ur.user_id left join t_roles r on ur.role_id = r.id where r.role_type = 'security_manager' and udg.group_id = #{id}")
	public List<SelectUserDTO> getSecurityManagers(String id);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getSecurityPatrol   
	 * @Description: 根据设备组id获取巡检员
	 */
	@Select("select u.id,u.name from t_users u inner join t_users p on u.parent_id = p.id left join t_user_role ur on u.id = ur.user_id left join t_roles r on ur.role_id = r.id where r.role_type = 'security_patrol' and p.id = #{id}")
	public List<SelectUserDTO> getSecurityPatrol(String id);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getSendUsersByNoticeId   
	 * @Description: 根据消息id获取要发送消息推送的用户  
	 */
	public List<MessageUserDto> getSendUsersByNoticeId(@Param("noticeId") String noticeId);
	
	
	/**
	 * @author liuxincheng
	 * @Title: getUserByParentId
	 * @Description: TODO(通过父级Id找到该用户的管理员)
	 * @param @param parentId
	 * @param @return    设定文件
	 * @return User    返回类型
	 * @throws null
	 */
	@Select("select u.* from t_users u where u.parent_id=#{parentId}")
	public User getUserByParentId(@Param("parentId")String parentId);
	
	/**
	 * @author liuxincheng
	 * @Title: getUserByCondition
	 * @Description: TODO(校验用户信息)
	 * @param @param telphoneNumber
	 * @param @param passWord
	 * @param @return    设定文件
	 * @return User    返回类型
	 * @throws null
	 */
	@Select("select u.* from t_users u where u.tel_number = #{telphoneNumber} and u.password =#{passWord}")
	public User getUserByCondition (@Param("telphoneNumber")String telphoneNumber,@Param("passWord")String passWord);
	
	/**
	 * @author liuxincheng
	 * @Title: updateUserInfo
	 * @Description: TODO(修改用户状态)
	 * @param @param userId
	 * @param @param enable
	 * @param @return    设定文件
	 * @return int    返回类型
	 * @throws
	 */
	@Update("update t_users u set u.enable = #{enable} where u.id = #{userId}")
	public int updateUserInfo (@Param("userId")String userId,@Param("enable")boolean enable);
	
	/**
	 * @author: xiechengguang 
	 * @Title: findOneById   
	 * @Description: TODO  
	 */
	public UserInfo findOneById(@Param("userId")String userId);
	
	
}
